/// @see https://dtolnay.github.io/rust-quiz/27
trait Base {
    fn method(&self) -> u32 {
        1
    }
}

trait Derived: Base {
    fn method(&self) -> u32 {
        2
    }
}

struct BothTraits;
impl Base for BothTraits {}
impl Derived for BothTraits {}

fn dynamic_dispatch(x: &dyn Base) -> u32 {
    x.method()
}

fn static_dispatch<T: Base>(x: T) -> u32 {
    x.method()
}

fn main() {
    print!("{}", dynamic_dispatch(&BothTraits));
    print!("{}", static_dispatch(BothTraits));
}

#[test]
fn test() {
    assert_eq!(1, dynamic_dispatch(&BothTraits));
    assert_eq!(1, static_dispatch(BothTraits));
}
